package com.example.administrator.xtu_community.fragment;

import static android.content.ContentValues.TAG;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.example.administrator.xtu_community.Adapter.ImageBannerAdapter;
import com.example.administrator.xtu_community.Adapter.SearchFragmentAdapter;
import com.example.administrator.xtu_community.R;
import com.example.administrator.xtu_community.activity.MeetingAct;
import com.example.administrator.xtu_community.simpleClass.DataBean;
import com.example.administrator.xtu_community.simpleClass.SearchFragmentData;
import com.youth.banner.Banner;
import com.youth.banner.indicator.CircleIndicator;
import com.youth.banner.transformer.DepthPageTransformer;

import java.util.ArrayList;
import java.util.List;

/**
 * SearchFragment
 * 用于提供多种服务入口
 * 如会议室预约
 * 了解各小组情况及加入方式
 * 比赛报名登记
 */
public class SearchFragment extends Fragment {
    private Banner banner;
    private List<DataBean> mBeans = new ArrayList<>();
    private Button group;
    private Button contest;
    private Button bookMeeting;
    private RecyclerView recyclerView;
    private  List<SearchFragmentData> list1 = new ArrayList<>();
    private  List<SearchFragmentData> list2 = new ArrayList<>();

    public SearchFragment() {
    }

    public static SearchFragment newInstance() {
        SearchFragment fragment = new SearchFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
        }
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        group = (Button) getActivity().findViewById(R.id.group);
        contest = (Button) getActivity().findViewById(R.id.contest);
        bookMeeting = (Button) getActivity().findViewById(R.id.bookMeeting);

        group.setTextColor(getResources().getColor(R.color.blue));
        group.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e(TAG, "onClick: " + "点击了小组按钮");
                group.setTextColor(getResources().getColor(R.color.blue));
                contest.setTextColor(getResources().getColor(R.color.colorPrimary));
                bookMeeting.setTextColor(getResources().getColor(R.color.colorPrimary));
                recyclerView.setAdapter(new SearchFragmentAdapter(list1));
            }
        });

        contest.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e(TAG, "onClick: " + "点击了竞赛按钮");
                group.setTextColor(getResources().getColor(R.color.colorPrimary));
                contest.setTextColor(getResources().getColor(R.color.blue));
                bookMeeting.setTextColor(getResources().getColor(R.color.colorPrimary));
                recyclerView.setAdapter(new SearchFragmentAdapter(list2));
            }
        });

        bookMeeting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e(TAG, "onClick: " + "点击了预约按钮");
                group.setTextColor(getResources().getColor(R.color.colorPrimary));
                contest.setTextColor(getResources().getColor(R.color.colorPrimary));
                bookMeeting.setTextColor(getResources().getColor(R.color.blue));
                Intent intent = new Intent(getActivity() , MeetingAct.class);
                startActivity(intent);
            }
        });
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_search, container, false);
        initList();

        banner = (Banner) view.findViewById(R.id.banner);
        recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setAdapter(new SearchFragmentAdapter(list1));


        ImageBannerAdapter imageBannerAdapter = new ImageBannerAdapter(mBeans);
        banner.setAdapter(imageBannerAdapter)
                .addBannerLifecycleObserver(this)
                .setIndicator(new CircleIndicator(getContext()))
                .setPageTransformer(new DepthPageTransformer());

        return view;
    }

    private void initList() {
        DataBean dataBean1 = new DataBean(R.drawable.good_morning_img);
        mBeans.add(dataBean1);
        DataBean dataBean2 = new DataBean(R.drawable.good_night_img);
        mBeans.add(dataBean2);

        SearchFragmentData s1 = new SearchFragmentData("安卓小组");
        list1.add(s1);
        SearchFragmentData s2 = new SearchFragmentData("算法小组");
        list1.add(s2);
        SearchFragmentData s3 = new SearchFragmentData("深度学习小组");
        list1.add(s3);
        SearchFragmentData s4 = new SearchFragmentData("后端小组");
        list1.add(s4);
        SearchFragmentData s5 = new SearchFragmentData("前端小组");
        list1.add(s5);


        SearchFragmentData s6 = new SearchFragmentData("第十三届蓝桥杯正在火热举行中，快快报名！");
        list2.add(s6);
        SearchFragmentData s7 = new SearchFragmentData("第四届软件开源大赛即将结束，请大家最后冲刺！");
        list2.add(s7);
    }

}